import { createBrowserRouter, Navigate } from "react-router-dom";
import Main from "../pages/MainLayout/Mainlayout.tsx";
import Home from "../pages/home";
import User from "../pages/user";
import Product from "../pages/product";
import PayList from "../pages/list/PayList/index.tsx";
import UnPayList from "../pages/list/UnPayList/index.tsx";
import Login from "../pages/login";

import ErrorPage from "../pages/ErrorPage";

export const router = createBrowserRouter([
  {
    path: "/",
    element: <Main />,
    errorElement: <ErrorPage />,

    children: [
      { index: true, element: <Navigate to="/home" replace /> },
      { path: "home", element: <Home /> },
      { path: "user", element: <User /> },
      { path: "product", element: <Product /> },
      {
        path: "list",
        children: [
          { path: "paylist", element: <PayList /> },
          { path: "unpaylist", element: <UnPayList /> },
        ],
      },
    ],
  },
  {
    path: "/login",
    element: <Login />,
  },
  { path: "error", element: <ErrorPage /> },

  {
    path: "*",
    element: <Navigate to="/error" replace />,
  },
]);

export default router;
